//
//  ArrayUtil.m
//  BlocksKitSample
//
//  Created by 李勇 on 2018/9/9.
//  Copyright © 2018年 李勇. All rights reserved.
//

#import "ArrayUtil.h"
@import BlocksKit;
typedef BOOL(^judgeItem)(id);
@implementation ArrayUtil

+(void)test{
    NSArray *array = @[@"a",@"a",@"b",@"b",@"c",@"c"];
    [array bk_each:^(id obj) {
        NSLog(@"element:%@",obj);
    }];
    [array bk_apply:^(id obj) {
        NSLog(@"element:%@",obj);
    }];
    judgeItem judgeItem = ^(id obj){
        if ([obj isKindOfClass:[NSString class]]) {
            return [@"a" isEqualToString:obj];
        }
        else{
            return NO;
        }
    };
    id selectedItem = [array bk_match:^BOOL(id obj) {
        return judgeItem(obj);
    }];
    NSLog(@"selectedItem:%@",selectedItem);
    id selecedArray = [array bk_select:^BOOL(id obj) {
        return judgeItem(obj);
    }];
    NSLog(@"selecedArray:%@",selecedArray);
    NSArray *new = [array bk_map:^id(id obj) {
        if ([obj isKindOfClass:[NSString class]]) {
            return [@"pre" stringByAppendingString:obj];
        }
        else{
            return @"pre";
        }
    }];
    NSLog(@"newArray:%@",new);

}

@end
